 <template>
    <div>
        <el-row>
            <!--检索-->
            <el-form :inline="true" :model="search" class="demo-form-inline">
                <el-input v-if="false" v-model="search.pageNo"></el-input>
                <el-input v-if="false" v-model="search.pageSize"></el-input>
                <el-col :span="4">
                    <el-input v-model="search.clientName" placeholder="请输入会员名称"></el-input>
                </el-col>
                <el-col :span="12"><div>
                        <el-button type="primary" icon="el-icon-search" @click="searchBtn">搜索</el-button>
                        <!-- <el-button type="info" icon="el-icon-loading" @click="emptyBtn">刷新</el-button> -->
                    </div>
                </el-col></el-form>

            <!--功能列表-->
            <el-table :data="tableData" style="width: 100%">
                <el-table-column type="index" label="#" sortable> </el-table-column>
                <el-table-column prop="clientName" label="会员名称"> </el-table-column>
                <el-table-column  label="创建时间" width="175px">
                    <template slot-scope="scope">
                        <i class="el-icon-time"></i>
                        <span style="margin-left: 10px">{{ scope.row.createTime | dateFilter("yyyy-mm-dd hh:mm:ss")  }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="changeType" :formatter="getChangeName" label="积分变化类型" width="160px"> </el-table-column>
                <el-table-column prop="changeCount" label="积分改变数量"> </el-table-column>
                <el-table-column prop="operateMan" label="操作人"> </el-table-column>
                <el-table-column prop="operateNote" label="操作备注"> </el-table-column>
                <el-table-column prop="sourceType" :formatter="getSourceName" label="积分来源"> </el-table-column>
                <el-table-column  label="添加时间" width="175px">
                    <template slot-scope="scope">
                        <i class="el-icon-time"></i>
                        <span style="margin-left: 10px">{{ scope.row.addtime | dateFilter("yyyy-mm-dd hh:mm:ss")  }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="small" @click="deleteInfo(scope.$index, scope.row)" icon="el-icon-delete" type="danger">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页功能-->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page.pageNo"
                :page-sizes="[1, 5, 10, 20, 100]"
                :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.total"
            >
            </el-pagination>
        
        </el-row>
    </div>
</template>

<script>

export default {
    data() {
        return {
            tableData: [], 
            page: {},
            form: { status: '0' },
            search: { pageNo: 1, pageSize: 5 },
            formLabelWidth: '80px',
            dialogTableVisible: false
        };
    },
    created: function () {
        this.load();
    },
    methods: {
        //初始化数据
        load() {
            var _this = this;
            //页面初始化时，加载的方法
            this.$http.get('/api/mbs/integrationHistory/queryAllByParam?pageNo='+this.search.pageNo+'&pageSize='+this.search.pageSize, {
                    params: {
                        clientName: this.search.clientName
                    }
                })
                .then((response) => {
                    console.log(response.data);
                    _this.tableData = response.data.data.list;
                    _this.page = response.data.data;
                    _this.total = response.data.data.total;
                });
        },
        //每页显示数量发生变化
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.search.pageSize = val;
            this.load();
        },
        //第几页发生变化
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.search.pageNo = val;
            this.load();
        },
        //查询
        searchBtn() {
            console.log(`当前页`);
            this.load();
        },
        emptyBtn() {
            this.search = {};
            this.search.pageNo = 1;
            this.search.pageSize = 5;
            this.load();
        },
        //获取积分变化类型
        getChangeName(row, column, cellValue) {
        return cellValue == 1 ? '增加' : cellValue == 2 ? '减少' : '不变';
        },
        //获取积分来源类型
        getSourceName(row, column, cellValue) {
        var tmpType = '';
                    if (cellValue == 0) {
                        tmpType = '自驾服务消费金额';
                    } else if (cellValue == 1) {
                        tmpType = '参与官方活动';
                    } else {
                        tmpType = '官网或者app顶专车或者个人消费';
                    }
                    return tmpType;
        },

        deleteInfo: function (index, row) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    var _this = this;
                    this.$http
                        .delete('/api/mbs/integrationHistory/deleteById?id=' + row.id)
                        .then(function (response) {
                            console.log(response);
                            if (response.status == 200) {
                                //重新加载数据
                                _this.load();
                                //提示成功
                                _this.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                            _this.$message.error('你错了。。。');
                        });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
        }
    },filters: {
                    //时间格式处理
                    dateFilter: function (data, format = "") {
                        var dt = new Date(data);
                        var y = dt.getFullYear();
                        var m = (dt.getMonth()+1).toString().padStart(2,"0");
                        var d = dt.getDate().toString().padStart(2,"0");
                        var h = dt.getHours().toString().padStart(2,"0");
                        var mm = dt.getMinutes().toString().padStart(2,"0");
                        var s = dt.getSeconds().toString().padStart(2,"0");
                        if (format.toLocaleLowerCase() === "yyyy-mm-dd" ||
                            format.toLocaleLowerCase() === "") {
                            return `${y}-${m}-${d}`;
                        } else if (format.toLocaleLowerCase() === "yyyy/mm/dd") {
                            return `${y}/${m}/${d}`;
                        } else if (format.toLocaleLowerCase() === "yyyy-mm-dd hh:mm:ss") {
                            return `${y}-${m}-${d} ${h}:${mm}:${s}`;
                        } else if (format.toLocaleLowerCase() === "yyyy/mm/dd hh:mm:ss") {
                            return `${y}/${m}/${d} ${h}:${mm}:${s}`;
                        } else {
                            return `输入的时间格式有误`;
                        }
                    },
                },
};
</script>
<style>
</style>